from django import forms
from apps.BaseForm import FormMixin
from apps.app_focus.models import Focus


class FocusForm(forms.ModelForm, FormMixin):
    title = forms.CharField(required=True,
                            max_length=20,
                            min_length=1)
    link_to = forms.URLField(required=True)
    thumbnail = forms.URLField(required=True)
    pub_time = forms.DateTimeField(required=True)
    end_time = forms.DateTimeField(required=True)
    priority = forms.IntegerField(required=True,
                                  min_value=1,
                                  max_value=99)

    class Meta:
        model = Focus
        fields = ('title', 'link_to', 'thumbnail', 'pub_time', 'end_time', 'priority')

        error_messages = {
            'title': {
                'require': '标题必填~~',
                'max_length': '标题长度 1 ~ 20 字符~~',
            },
            'link_to': {
                'require': '链接必填~~',
            },
            'thumbnail': {
                'require': '图片地址必填~~',
            },
            'pub_time': {
                'require': '时间范围必填~~',
            },
            'end_time': {
                'require': '时间范围必填~~',
            },
            'priority': {
                'require': '优先级必填~~',
                "min_value": '优先级范围 1-99 ~~',
                "max_value": '优先级范围 1-99 ~~',
            },
        }
